Try to not allocate when decoding registry json
authorAlex Crichton <alex@alexcrichton.com>
Fri, 2 Jun 2017 14:00:17 +0000 (07:00 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 5 Jun 2017 14:36:44 +0000 (07:36 -0700)
There's a few keys we don't need owned versions of, so try using Serde's
zero-copy deserialization where we can.

src/cargo/sources/registry/mod.rs

index 5319c4bfe6ec2df30f8eabfdfbf01bc4b7053d68..139d8a607b653a3f25af7f62cbcce2817d6acde4 100644 (file)
 //!         ...
 //! ```
 
+use std::borrow::Cow;
 use std::collections::HashMap;
 use std::fs::File;
 use std::path::{PathBuf, Path};
@@ -198,24 +199,24 @@ pub struct RegistryConfig {
 }
 
 #[derive(Deserialize)]
-struct RegistryPackage {
+struct RegistryPackage<'a> {
     name: String,
     vers: String,
-    deps: Vec<RegistryDependency>,
+    deps: Vec<RegistryDependency<'a>>,
     features: HashMap<String, Vec<String>>,
     cksum: String,
     yanked: Option<bool>,
 }
 
 #[derive(Deserialize)]
-struct RegistryDependency {
-    name: String,
-    req: String,
+struct RegistryDependency<'a> {
+    name: Cow<'a, str>,
+    req: Cow<'a, str>,
     features: Vec<String>,
     optional: bool,
     default_features: bool,
-    target: Option<String>,
-    kind: Option<String>,
+    target: Option<Cow<'a, str>>,
+    kind: Option<Cow<'a, str>>,
 }
 
 pub trait RegistryData {